package org.sudoku.solver;

/**
 * A base with common implementations.
 * 
 * @author shivkumar cm
 * 
 */
public abstract class BaseSolver implements ISolver {

	/**
	 * @see ISolver#inferAndApply()
	 */
	public boolean inferAndApply() {
		if (infer()) {
			applyInferences();
			prettyPrint();
			return true;
		} else {
			return false;
		}
	}

	/**
	 * @see ISolver#solve()
	 */
	public int solve() {
		int steps = 0;
		while (!solved()) {
			if (!inferAndApply()) {
				System.out.println("There is no progress...");
				break;
			}
			++steps;
		}
		if (solved()) {
			System.out.println("Solved in " + steps + " steps!!!");
		} else {
			System.out.println("Halted after " + steps + " steps.");
		}
		return steps;
	}

}
